﻿using NXDO.Data.Factory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TDM.DbData.DataEntity;

namespace TDM.WebBiz.Project
{
    public static class TestTaskHelper
    {
        public static bool DeleteTestTask(long id)
        {
            string sqltxt = "update TestTask set isdelete=true where TaskID={0}";
            var rs = DbHelper.SetUpdateCommand(sqltxt, id).ExecuteNonQuery();
            return rs > 0;
        }

        public static List<bool> DeleteTestTask(List<long> ids)
        {
            List<bool> results = new List<bool>();
            if (ids.Count <= 0) throw new ArgumentException("ids不能为空");
            foreach (var id in ids)
            {
                string sqltxt = "update TestTask set isdelete=true where TaskID={0}";
                var rs = DbHelper.SetUpdateCommand(sqltxt, id).ExecuteNonQuery();
                results.Add(rs > 0);
            }
            return results;
        }

        public static List<TestTask> QueryPrjTasks(long prjid)
        {
            string sqltxt = "select * from TestTask where PrjID={0} and isdelete<>1 order by CreateTime desc";
            var rs = DbHelper.SetCommand(sqltxt, prjid).ExecuteEntity<TestTask>().ToList();
            return rs;
        }

        public static List<TestTask> QueryPrjTasksIncludeDelete(long prjid)
        {
            string sqltxt = "select * from TestTask where PrjID={0} order by CreateTime desc";
            var rs = DbHelper.SetCommand(sqltxt, prjid).ExecuteEntity<TestTask>().ToList();
            return rs;
        }

        public static TestTask Get(long id)
        {
            string sqltxt = "select * from TestTask where taskid={0} ";
            var rs = DbHelper.SetCommand(sqltxt, id).ExecuteEntityScalar<TestTask>();
            return rs;
        }
    }
}
